package com.tx.blog.config;

import com.tx.blog.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：tx
 * @description：过滤器配置类
 * @date ：Created in 2019/4/28 16:27
 * @modified By：
 * @version: 1.0
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * @author tx
     * @description  设置访问controller返回的视图
     * @date  2019/4/28 16:28
     * @param  * @Param: registry
     * @return void
    **/
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login")
                .setViewName("login/login");
    }

    /**
     * @author tx
     * @description  设置拦截器
     * @date  2019/4/28 16:28
     * @param  * @Param: registry
     * @return void
    **/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> list = new ArrayList<>();
        //list.add("/index");
        list.add("/login");
        list.add("/toLogin/**");
        list.add("/error");
        list.add("/UserController/registerUser");
        list.add("/inter/**");

        /**
         * 静态资源
         */
        list.add("/framework/**");
        list.add("/login/**");
        list.add("/common/**");
        list.add("/summernote/**");
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(list);
    }
}
